program Colors;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  arrint = array of Integer;

var
  e, v, i, j, col, c, c1, c2: Integer;
  color: arrint;
  flag: Boolean;

begin
  read(v, e);

  SetLength (color, v);
  for i:=1 to v do
  begin
    color[i-1]:=i;
  end;

  for i:=0 to e-1 do
  begin
    read(c1, c2);
    c1:=c1-1;
    c2:=c2-1;
    if color[c1] <> color[c2] then
    begin
      col:=color[c1];
      for j:=0 to v-1 do
      begin
        if color[j] = col then
        begin
          color[j]:=color[c2];
        end;
      end;
    end;
  end;

  flag:= False;
  for i:=1 to v do
  begin
    c:=i;
    for j:=0 to v-1 do
    begin
      if color[j] = c then
      begin
        write(j+1, ' ');
        flag:=True;
      end;
    end;
    if flag = True then
    begin
      Writeln;
      flag:=False;
    end;
  end;

  Readln;
  Readln;
end.
